package org.lds.logger.config.level;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public enum Level {
    DEBUG(100),
    INFO(200),
    WARN(700),
    ERROR(800),
    ;

    public int code;

    public int getCode() {
        return code;
    }

    Level(int code) {
        this.code = code;
    }

    private static final Map<String, Level> LEVEL_MAP;
    static {
        LEVEL_MAP = new HashMap<>();
        LEVEL_MAP.put("DEBUG".toLowerCase(), DEBUG);
        LEVEL_MAP.put("INFO".toLowerCase(), INFO);
        LEVEL_MAP.put("WARN".toLowerCase(), WARN);
        LEVEL_MAP.put("ERROR".toLowerCase(), ERROR);
    }

    public static Level getLevel(String levelStr) {
        if (StringUtils.isEmpty(levelStr)) return DEBUG;
        Level level = LEVEL_MAP.get(levelStr.toLowerCase());
        if (level == null) return DEBUG;
        return level;
    }

}
